#!/usr/bin/python

from tkinter import *
# 导入ttk
from tkinter import ttk
# 导入filedialog
from tkinter import filedialog


class App:
    def __init__(self, master):
        self.master = master
        self.is_open_type = False  # False表示当前未开启，True表示当前开启
        self.str = StringVar()
        self.str.set('0天 00：00：00')
        self.initWidgets()

    def initWidgets(self):
        print(self.str.get())
        self.lable_title = ttk.Label(self.master, text='麦嘎FTP自动同步文件', background="white", font=("微软雅黑", 20))
        self.lable_time = ttk.Label(self.master, textvariable=self.str, font=("微软雅黑", 28), foreground='blue',
                                    background='red')
        self.button_sync = ttk.Button(self.master, text='开启同步', command=self.sync_file)
        self.button_down_files = ttk.Button(self.master, text='选择本地下载目录', command=self.open_directory)
        self.button_jason_file = ttk.Button(self.master, text='Jason配置文件', command=self.open_jason_file)

        self.lable_title.grid(row=1, column=1, columnspan=2, pady=10)
        self.lable_time.grid(row=2, column=1, columnspan=2)
        self.button_sync.grid(row=3, column=1, columnspan=2, pady=10)
        self.button_down_files.grid(row=4, column=1, padx=35, pady=20)
        self.button_jason_file.grid(row=4, column=2, padx=35, pady=20)

    def sync_file(self):

        if self.is_open_type == False:
            self.button_sync['text'] = '关闭'
            self.str.set('修改的内容为关闭')
            self.is_open_type = True
        else:
            self.button_sync['text'] = '开启同步'
            self.str.set('修改的内容为开启')
            self.is_open_type = False
        print(self.lable_title['text'])

    def open_directory(self):
        # 调用askdirectory方法打开目录
        print(filedialog.askdirectory(title='打开目录', initialdir='d:/'))  # 初始目录

    def open_jason_file(self):
        pass


root = Tk()
root.title('集团FTP自动下载文件')
root.geometry("400x200+200+200")
App(root)
root.mainloop()
